package com.saile.service;

import com.saile.dao.AlbumMapper;
import com.saile.domain.Album;
import com.saile.myRunTime.MyRunTimeExcption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2018-4-27.
 */
@Service
public class AlbumServiceImpl extends BaseService implements AlbumService {
    @Autowired
    AlbumMapper albumMapper;
    @Autowired
    MediaService mediaService;

    private void insertAlbum(Album album) {
        albumMapper.insertAlbum(album);
    }

    private void updateAlbum(Album album) {
        // mediaMapper.updateByPrimaryKeySelective(advert);
    }

    @Override
    public void modifyAlbum(Album album) throws MyRunTimeExcption {
        if (album.getTid() == null) {
            insertAlbum(album);
            return;
        }
        updateAlbum(album);
    }

    @Transactional
    @Override
    public void deleteAlbumById(Long albumId) throws MyRunTimeExcption {
        albumMapper.deleteAlbumById(albumId);
        Map<String, String> map = new HashMap<>();
        map.put("albumId", String.valueOf(albumId));
        mediaService.deleteMedia(map);
    }

    @Override
    public List<Album> getAlbumList(Map<String, String> map) throws MyRunTimeExcption {
        return albumMapper.getAlbumList(map);
    }

    @Override
    public Album getAlbum(Map<String, String> map) throws MyRunTimeExcption {
        return albumMapper.getAlbum(map);
    }
}
